/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * @author zhouqh
 * Date: 2010-5-24 下午02:15:11
 */
package com.ccxe.manage.db;

import java.sql.Connection;
import java.sql.ResultSet;
/**
 * @author zhouqh
 *
 */
public interface CcxDB {
	/**
	 * 执行不带参数的查询
	 * @param sqlKey 要执行的SQL语句的Key
	 * @return 查询结果
	 * @throws DatabaseException 如果发生错误
	 */
	public ResultSet executeQuery(String sqlKey) throws Exception;
	
	/**
	 * 执行带有分页功能的查询
	 * @param sql
	 * @param pageCount
	 * @param limit
	 * @return
	 * @throws Exception
	 */
	public ResultSet executeQuery(String sql,int pageCount,int limit) throws Exception; 

	/**
	 * 执行带参数的查询
	 * @param sqlKey 要执行的SQL语句的Key
	 * @param sqlParameters 查询参数
	 * @return 包含该查询生成的数据�?ResultSet 对象；从不返�?null
	 * @throws DatabaseException 如果发生错误
	 */
	public ResultSet executeQuery(String sqlKey, Object[] sqlParameters)
			throws Exception;

	/**
	 * 执行更新
	 * @param sqlKey 要执行的SQL语句的Key
	 * @param sqlParameters 查询参数
	 * @return (1) 对于 INSERT、UPDATE �?DELETE 语句，返回行�?(2) 或�?对于�?��都不返回�?SQL 语句，返�?0
	 * @throws Exception 如果发生错误
	 */
	public int executeUpdate(String sqlKey, Object[] sqlParameters)
			throws Exception;

	/**
	 * 得到查询结果的�?�?
	 * @param sql 用于计算查询结果的sql语句,�?select count(*) from tableName
	 * @return 结果总数
	 * @throws Exception 如果发生错误
	 */
	public int getSearchTotalRowSize(String sql) throws Exception;
	
	/**
	 * 得到查询结果的�?�?
	 * @param countSqlKey 用于计算查询结果的sql语句在属性文件中的Key
	 * @param sqlParameters 查询参数
	 * @return 查询结果总数
	 * @throws Exception 如果发生错误
	 */
	public int getSearchTotalRowSize(String countSqlKey, Object[] sqlParameters)
	throws Exception;
//	/**
//	 * 用于执行分页查询
//	 * @param sql 查询的sql语句
//	 * @param criteria 包含查询参数，如每页大小，当前页�?
//	 * @return 当前页的结果�?
//	 * @throws Exception 如果发生错误
//	 */
//	public ResultSet executeSearch(String sql, SearchCriteria criteria)
//			throws Exception;
	
//	/**
//	 * 用于执行分页查询
//	 * @param searchSqlKey 查询的sql语句在属性文件中的Key
//	 * @param criteria 包含查询参数，如每页大小，当前页�?
//	 * @param sqlParameters 查询参数
//	 * @return 当前页的结果�?
//	 * @throws Exception
//	 */
//	public ResultSet executeSearch(String searchSqlKey,
//			SearchCriteria criteria, Object[] sqlParameters)
//			throws Exception;

	/**
	 * 得到PaymentDB中的数据库连接对象，只供特殊情况下使用，平时应尽量避免直接使用此函数
	 * @return <code>Connection</code>对象
	 * @throws Exception 如果发生错误
	 */
	public Connection getConnection() throws Exception;

	/**
	 * Close all statements and connection to the database.
	 * 
	 * @throws DatabaseExeption
	 *             if an error occurs during close procedures
	 */
	public void close() throws Exception;

	/**
	 * Close the statement object associated with the query.
	 * 
	 * @param sqlKey
	 *            the name of a query previously passed to an executeQuery or
	 *            executeUpdate method.
	 * 
	 * @throws Exception if unable to close the statement
	 */
	public void close(String sqlKey) throws Exception;

	/**
	 * Commit the preceeding transactions
	 * 
	 * @throws Exception
	 *             if unable to execute the commit
	 */
	public void commit() throws Exception;

	/**
	 * Rollback the preceeding transactions
	 * 
	 * @throws Exception
	 *             if unable to execute the rollback
	 */
	public void rollback() throws Exception;

	/**
	 * Set the AutoCommit mode for the connection.
	 * 
	 * @throws Exception
	 *             if unable to execute the AutoCommit
	 */
	public void setAutoCommit(boolean mode) throws Exception;

	/**
	 * Get the next message number.
	 * 
	 * @return next message number
	 * @throws Exception
	 *             if any database error occurs
	 */
	public long getNextMsgNumber() throws Exception;

	/**
	 * Get the next address number.
	 * 
	 * @return next address number
	 * @throws Exception
	 *             if any database error occurs
	 */
	public long getNextAddressNumber() throws Exception;
}
